#!/usr/bin/env bash

# check if running as root user
if [ "$EUID" -ne 0 ]; then
	echo -e "This script needs to run as root user, please use \"sudo ./uninstall\" instead";
	exit 1;
fi



# removing vortex-ubuntu in the list of aviable themes
echo -n "updating plymouth themes alternatives   ........................   " ;
update-alternatives --remove default.plymouth /usr/share/plymouth/themes/vortex-ubuntu/vortex-ubuntu.plymouth &> /dev/null ;
if [ $? -gt 0 ]; then
	echo -e "\nan error occoured removing alternative in /usr/share/plymouth/themes/default.plymouth" ;
	exit 1;
fi
echo "[done]" ;



# setting a new default plymouth theme;
echo "asking user to set a different theme   ......   ...................   [done]" ;
echo -e "\nDEFAULT OPTIONS ARE:" ;
echo -e "for Ubuntu 20.04   ...   1  /usr/share/plymouth/themes/bgrt/bgrt.plymouth\n" ;
update-alternatives --config default.plymouth  ;
if [ $? -gt 0 ]; then
	echo -e "\nan error occoured setting alternative in /usr/share/plymouth/themes/default.plymouth";
	n=0 ;
	while [ $? -gt 0 -a $n -le 3 ]; do
		update-alternatives --config default.plymouth  ;
		n=$(( n+1 )) ;
	done
	exit 1;
fi



# updating Initial RAM File System
echo -n "updating Initial RAM File System   .............................   " ;
update-initramfs -u &> /dev/null ;
if [ $? -gt 0 ]; then
	echo -e "\nan error occoured executing \"update-initramfs -u\"";
	exit 1;
fi
echo "[done]" ;



# check if plymouth themes directory exist
if [ -d "/usr/share/plymouth/themes/vortex-ubuntu" ]; then
	echo -n "removing /usr/share/plymouth/themes/vortex-ubuntu   ............   " ;
	rm -r /usr/share/plymouth/themes/vortex-ubuntu ;
	if [ $? -gt 0 ]; then
		echo -e "\nan error occoured removing /usr/share/plymouth/themes/vortex-ubuntu" ;
		exit 1;
	fi
	echo "[done]" ;
fi
